import * as React from 'react';
import { NavLink } from 'react-router-dom';
// import { withRouter } from 'react-router'
// import {observable, autorun, computed, action} from 'mobx';
import Comm from "src/config/comm";

import "./Login.scss";
import { connect } from 'react-redux';
import { loginOut , getUserInfo } from "src/stores/userinfo/action";
function Login(props:any){
  console.log(props);
  // 初始化用户信息
  const {userData} = props;
  
  

  return (
    <div>
      {
        props.userData &&
        (
          <div className="_logined">
            {userData.name}
            <ul className="nvs">
              <li><NavLink exact={true} to="/self/boke/center" >账户中心</NavLink></li>
              <li><NavLink exact={true} to="/self/boke" >我的博客</NavLink></li>
              <li onClick={props.loginOut}>退出登录</li>
            </ul>
          </div>
        )
      }
       {
         !props.userData &&
         <div className="_login">
          <span onClick={Comm.toLogin.bind(null,2)}>注册</span>
          <span onClick={Comm.toLogin.bind(null,1)}>登录</span>
         </div>
       }
    </div>
   
  );
}

export default connect((state:any) => ({
  userData: state.userInfo,   // 传入的数据 state
  }), {  // 传入的方法 action
  loginOut,
  getUserInfo
  })(Login);
